﻿using CoachingOrganizer.ClientInfrastructure.ServicesEntities.LocalStorage.Tools.MoneyCalculation;
using CoachingOrganizer.Logic.Common;
using CoachingOrganizer.Logic.Models.Tools.MoneyCalculation;
using CoachingOrganizer.Toolkit.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoachingOrganizer.Logic.Logic.Tools.MoneyCalculation
{
    internal class OccasionalMoneyFlowItemLogic
    {
        private readonly OccasionalMoneyFlowItemModel _model;
        private readonly LogicExtender _logicExtender;
        private readonly MoneyFlowLogic _upperLogic;
        private readonly IOccasionalMoneyFlowItemInfo _localData;
        
        public OccasionalMoneyFlowItemModel Model
        {
            get { return _model; }
        }

        public IOccasionalMoneyFlowItemInfo LocalData
        {
            get { return _localData; }
        } 

        public OccasionalMoneyFlowItemLogic(OccasionalMoneyFlowItemModel model, LogicExtender logicExtender, MoneyFlowLogic upperLogic, IOccasionalMoneyFlowItemInfo localData)
        {
            _model = model;
            _logicExtender = logicExtender;
            _upperLogic = upperLogic;
            _localData = localData;
            model.RemoveDelegate = Remove;
            model.SaveDelegate = Save;
        }

        public bool GetIsInPeriod(DateTime start, DateTime end)
        {
            return _model.Time > start && _model.Time < end;
        }

        private ActionResult Remove()
        {
            return _upperLogic.RemoveOccasionalItem(this);
        }

        private ActionResult Save()
        {
            _localData.Name = _model.Name;
            _localData.Time = _model.Time;
            _localData.Amount = _model.Amount;
            return _localData.Save();
        }
    }
}
